package sys.person;

import sys.database.Database;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Judge extends AbstractPerson{

    String eventID;
    String eventName;

    public Judge(String id, String name, String eventID, String eventName) {
        super(id, name);
        this.eventID = eventID;
        this.eventName = eventName;
    }

    public Judge(String id) {
        super(id, "");
    }

    public Judge(String id, String eventID) {
        super(id, "");
        this.eventID = eventID;
    }

    public String getEventID() {
        return eventID;
    }

    public void setEventID(String eventID) {
        this.eventID = eventID;
    }

    public String getEventName() {
        return eventName;
    }

    public void setEventName(String eventName) {
        this.eventName = eventName;
    }

    // OK
    public void markForPlayer(String playerID, double score) {
        String sql = "update player set score = ? where playerID = " + playerID + " and eventID = " + eventID;
        PreparedStatement preparedStatement = new Database().createConnection(sql);

        try {
            preparedStatement.setDouble(1, score);
            preparedStatement.executeUpdate();
        } catch (SQLException e) {
            System.out.println("判分失败！");
        }
    }

    /**
     * 查看自己的报名项目
     */
    // OK
    public void checkMyEvent() {
        String sql = "select * from judge where judgeID = " + getId();
        Database database = new Database();
        Statement stmt = database.createConnection();
        try {
            ResultSet resultSet = stmt.executeQuery(sql);
            System.out.println("你的报名项目：");
            System.out.println("项目编号" + "   " + "项目名称");
            while (resultSet.next()) {
                String eventID = resultSet.getString("eventID");
                String eventName = resultSet.getString("eventName");
                System.out.println(eventID + "     " + eventName);
            }
        } catch (SQLException e) {
            System.out.println("查找失败！");
        }
    }
}
